home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / doors / cli / clidoor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  2.2 KB  |  109 lines

  1. #include <exec/exec.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <dos/dos.h>
  5. #include <dos/dosextens.h>
  6. void LastCommand(void);
  7. void end(void);
  8. char WindowName[255];
  9. VOID
  10. SendAmigaDOSCommand(UBYTE *Name);
  11. struct ConUnit *
  12. GetConUnit(struct MsgPort *ConsoleTask);
  13.  
  14. struct CommandLineInterface *temp=NULL;
  15. #define sm sendmessage
  16. main(int argc,char *argv[])
  17. {
  18.    Register(argv[1][0]-'0');
  19.    temp=(struct CommandLineInterface *)Cli();
  20.    if(temp)
  21.    {
  22.       sm("Yes there is a commandline interface for this door.",1);
  23.    }
  24.    else sm("Can't locate a commandline interface.",1);
  25.    
  26.    ShutDown();
  27.    end();
  28. }
  29.  
  30. void LastCommand(void)
  31. {
  32. }
  33. void end(void)
  34. {
  35.   exit(0);
  36. }
  37.  
  38. strcpy(WindowName,"CON:0/11//100/term Output Window/CLOSE/SCREEN TERM");
  39. struct ConUnit *
  40. GetConUnit(struct MsgPort *ConsoleTask)
  41. {
  42.     struct InfoData    *InfoData;
  43.     struct ConUnit    *ConUnit = NULL;
  44.  
  45.     if(!ConsoleTask)
  46.         ConsoleTask = (struct MsgPort *)((struct Process *)SysBase -> ThisTask) -> pr_ConsoleTask;
  47.  
  48.     if(InfoData = (struct InfoData *)AllocVec(sizeof(struct InfoData),MEMF_ANY|MEMF_CLEAR))
  49.     {
  50.             /* Send the inquiry packet to the console task. */
  51.  
  52.         if(DoPkt1(ConsoleTask,ACTION_DISK_INFO,MKBADDR(InfoData)))
  53.             ConUnit = (struct ConUnit *)((struct IOStdReq *)InfoData -> id_InUse) -> io_Unit;
  54.  
  55.         FreeVec(InfoData);
  56.     }
  57.  
  58.     return(ConUnit);
  59. }
  60.  
  61.  
  62. VOID
  63. SendAmigaDOSCommand(UBYTE *Name)
  64. {
  65.     BYTE DummyBuffer[2];
  66.     BPTR File;
  67.  
  68.         /* Let the asynchronous Rexx server pick up and process
  69.          * all incoming messages rather than sending them to the
  70.          * main process (hopefully avoids deadlock situations).
  71.          */
  72.  
  73.     //BatchMode = TRUE;
  74.  
  75.         /* Open the console window or whatever the user
  76.          * wants us to open here.
  77.          */
  78.  
  79.     if(File = Open(WindowName,MODE_NEWFILE))
  80.     {
  81.         struct ConUnit *ConUnit = GetConUnit(((struct FileHandle *)BADDR(File)) -> fh_Type);
  82.  
  83.         if(ConUnit)
  84.         {
  85.             if(ConUnit -> cu_Window)
  86.                 BumpWindow(ConUnit -> cu_Window);
  87.         }
  88.  
  89.             /* Make the Shell execute the command. */
  90.  
  91.         SystemTags(Name,SYS_Output,File,TAG_DONE);
  92.  
  93.             /* Wait for some impressive user action. */
  94.  
  95.         Write(File,LocaleString("Hello there"),51);
  96.  
  97.         Read(File,DummyBuffer,1);
  98.  
  99.         Close(File);
  100.     }
  101.  
  102.         /* Bring the `term' main screen to the front and
  103.          * fall back into asynchronous Rexx message processing.
  104.          */
  105.  
  106.     //BumpWindow(Window);
  107.  
  108.     //BatchMode = FALSE;
  109. }